package com.xsy.de.restful.controller;

import com.xsy.de.entity.ResultMsg;
import com.xsy.de.service.impl.SmsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rest/sms")
@Api(tags = "短信验证码接口", description = "短信验证码接口")
public class SmsRestController {
    private final static Logger log = LogManager.getLogger(SmsRestController.class);

    @Autowired
    private SmsServiceImpl smsService;

    /**
     * 发送短信验证码
     * @param phone
     * @param code
     * @return
     */
    @ApiOperation(value="发送短信验证码", notes="给指定手机号发送短信验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "手机号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "code",value = "验证码", required = true, dataType = "string",paramType = "query"),
    })
    @RequestMapping(value = "/sendCode", method = RequestMethod.POST, produces= MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultMsg sendCode(@RequestParam String phone, @RequestParam String code) {

        return smsService.sndSmsCode(phone, code);
    }

}
